<template>
	<div>
		<router-link tag="div" to="/" class="header-abs" v-show="showAbs"  >
			<div class="iconfont header-abs-icon">&#xe624;</div>
		</router-link>
		<div class="header-fixed" v-show="!showAbs" :style="opcityStyle"  >
			<router-link to='/' >
				<div class="iconfont header-back">&#xe624;</div>
			</router-link>
				景点详情
		</div>
	</div>
</template>

<script type="text/javascript">
	export default {
		name: 'DetailHeader',
		data(){
			return {
				showAbs: true,
				opcityStyle: {
					opacity: 0
				}
			}
		},
		methods: {
			handleScroll(){
				const topValue = document.documentElement.scrollTop;
				if(topValue > 60){
					let opacity = topValue / 140
					opacity = opacity>1?1:opacity
					this.opcityStyle = {
						opacity
					}
					this.showAbs = false
				}else{
					this.showAbs = true
				}
			}
		},
		mounted () {
			window.addEventListener('scroll',this.handleScroll)
		},
		// 对全局事件进行解绑，防止该页面组件影响其他页面组件
		unmounted () {
			window.removeEventListener('scroll',this.handleScroll)
		}
	};
</script>

<style lang="stylus" scoped>
	@import '~styles/varibles.styl'
	.header-abs
		position: absolute
		left: .2rem
		top: .4rem
		width: .8rem
		height: .8rem
		border-radius: .4rem
		background: rgba(0,0,0,.8)
		text-align: center
		line-height:.8rem
		.header-abs-icon
			color: #fff
			font-size: .4rem
	.header-fixed
		position: fixed 
		top: 0
		left: 0
		right: 0
		z-index: 9999
		height: $headerHeight
		line-height: $headerHeight
		background: $bgColor
		color: #fff
		font-size: .32rem
		text-align: center
		.header-back
			color: #fff
			width: .64rem
			text-align: center
			font-size: .4rem
			position: absolute
			left: 0
			top: 0
			color: #fff
</style>